home *** CD-ROM | disk | FTP | other *** search
/ Qoole for Quake / Qoole for Quake (USA) / Qoole for Quake (USA).bin / Tutorial / HTML / QUBE.ZIP / SRC / BSP5.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-05  |  8.5 KB  |  324 lines

  1.  
  2. /* bsp5.h */
  3.  
  4. #include "cmdlib.h"
  5. #include "mathlib.h"
  6. #include "bspfile.h"
  7.  
  8. typedef struct
  9. {
  10.     vec3_t    normal;
  11.     double    dist;
  12.     int        type;
  13. } plane_t;
  14.  
  15.  
  16. #include "map.h"
  17.  
  18. #define    MAX_THREADS    4
  19.  
  20. #define    ON_EPSILON    0.01
  21. #define    BOGUS_RANGE    18000
  22.  
  23. /* the exact bounding box of the brushes is expanded some for the headnode
  24.    volume.  is this still needed? */
  25. #define    SIDESPACE    24
  26.  
  27. /*===========================================================================*/
  28.  
  29.  
  30. typedef struct
  31. {
  32.     int        numpoints;
  33.     vec3_t    points[8];            /* variable sized */
  34. } winding_t;
  35.  
  36. #define MAX_POINTS_ON_WINDING    64
  37.  
  38. winding_t *BaseWindingForPlane (plane_t *p);
  39. void CheckWinding (winding_t *w);
  40. winding_t    *NewWinding (int points);
  41. void        FreeWinding (winding_t *w);
  42. winding_t    *CopyWinding (winding_t *w);
  43. winding_t    *ClipWinding (winding_t *in, plane_t *split, qboolean keepon);
  44. void    DivideWinding (winding_t *in, plane_t *split, winding_t **front, winding_t **back);
  45.  
  46. /*==========================================================================*/
  47.  
  48. void ScrnInit(void);
  49. void ShowStatusEntry(char *format, ...);
  50. void ShowTempEntry(char *format, ...);
  51. void ShowWarningEntry(char *format, ...);
  52. void PercentBar(int percent);
  53. void MajorPercentBar(int percent);
  54. void TimeUpdate(void);
  55. void CfPrintf(FILE *file, char *format, ...);
  56. void *qmalloc(int size);
  57. void qfree(void *mem);
  58.  
  59. extern int    StatusLine;        /* Output line for status info */
  60. extern long int StartTime;
  61. extern long int LastCheck;
  62. extern int    TotalStatusEntries;    /* How many status entries have gone by (out of 32) */
  63. extern int    CurPercent;
  64. extern int    CurMajorPercent;
  65. extern FILE    *LogFile;
  66.  
  67. extern long int TotalAlloc;
  68.  
  69. /*==========================================================================*/
  70.  
  71. #define    MAXEDGES            32
  72. #define    MAXPOINTS            28        /* don't let a base face get past this */
  73.                                     /* because it can be split more later */
  74.  
  75. typedef struct visfacet_s
  76. {
  77.     struct visfacet_s    *next;
  78.     
  79.     int                planenum;
  80.     int                planeside;    /* which side is the front of the face */
  81.     int                texturenum;
  82.     int                contents[2];    /* 0 = front side */
  83.  
  84.     struct visfacet_s    *original;        /* face on node */
  85.     int                outputnumber;        /* only valid for original faces after */
  86.                                         /* write surfaces */
  87.     int                numpoints;
  88.     vec3_t            pts[MAXEDGES];        /* FIXME: change to use winding_t */
  89.     int                edges[MAXEDGES];
  90. } face_t;
  91.  
  92.  
  93. typedef struct surface_s
  94. {
  95.     struct surface_s    *next;
  96.     struct surface_s    *original;    /* before BSP cuts it up */
  97.     int            planenum;
  98.     int            outputplanenum;        /* only valid after WriteSurfacePlanes */
  99.     vec3_t        mins, maxs;
  100.     qboolean        onnode;                /* true if surface has already been used */
  101.                                     /* as a splitting node */
  102.     face_t        *faces;    /* links to all the faces on either side of the surf */
  103. } surface_t;
  104.  
  105.  
  106. /* */
  107. /* there is a node_t structure for every node and leaf in the bsp tree */
  108. /* */
  109. #define    PLANENUM_LEAF        -1
  110.  
  111. typedef struct node_s
  112. {
  113.     vec3_t            mins,maxs;        /* bounding volume, not just points inside */
  114.  
  115. /* information for decision nodes     */
  116.     int                planenum;        /* -1 = leaf node     */
  117.     int                outputplanenum;    /* only valid after WriteNodePlanes */
  118.     int                firstface;        /* decision node only */
  119.     int                numfaces;        /* decision node only */
  120.     struct node_s    *children[2];    /* only valid for decision nodes */
  121.     face_t            *faces;            /* decision nodes only, list for both sides */
  122.     
  123. /* information for leafs */
  124.     int                contents;        /* leaf nodes (0 for decision nodes) */
  125.     face_t            **markfaces;    /* leaf nodes only, point to node faces */
  126.     struct portal_s    *portals;
  127.     int                visleafnum;        /* -1 = solid */
  128.     int                valid;            /* for flood filling */
  129.     int                occupied;        /* light number in leaf for outside filling */
  130. } node_t;
  131.  
  132. /*============================================================================= */
  133.  
  134. /* brush.c */
  135.  
  136. #define    NUM_HULLS        2                /* normal and +16 */
  137.  
  138. #define    NUM_CONTENTS    2                /* solid and water */
  139.  
  140. typedef struct brush_s
  141. {
  142.     struct brush_s    *next;
  143.     vec3_t            mins, maxs;
  144.     face_t            *faces;
  145.     int                contents;
  146. } brush_t;
  147.  
  148. typedef struct
  149. {
  150.     vec3_t        mins, maxs;
  151.     brush_t        *brushes;        /* NULL terminated list */
  152. } brushset_t;
  153.  
  154. extern    int            numbrushplanes;
  155. extern    plane_t        planes[MAX_MAP_PLANES];
  156.  
  157. brushset_t *Brush_LoadEntity (entity_t *ent, int hullnum);
  158. int    PlaneTypeForNormal (vec3_t normal);
  159. int    FindPlane (plane_t *dplane, int *side);
  160.  
  161. /*============================================================================= */
  162.  
  163. /* csg4.c */
  164.  
  165. /* build surfaces is also used by GatherNodeFaces */
  166. extern    face_t    *validfaces[MAX_MAP_PLANES];
  167. surface_t *BuildSurfaces (void);
  168.  
  169. face_t *NewFaceFromFace (face_t *in);
  170. surface_t *CSGFaces (brushset_t *bs);
  171. void SplitFace (face_t *in, plane_t *split, face_t **front, face_t **back);
  172.  
  173. /*============================================================================= */
  174.  
  175. /* solidbsp.c */
  176.  
  177. void DivideFacet (face_t *in, plane_t *split, face_t **front, face_t **back);
  178. void CalcSurfaceInfo (surface_t *surf);
  179. void SubdivideFace (face_t *f, face_t **prevptr);
  180. node_t *SolidBSP (surface_t *surfhead, qboolean midsplit);
  181.  
  182. /*============================================================================= */
  183.  
  184. /* merge.c */
  185.  
  186. void MergePlaneFaces (surface_t *plane);
  187. face_t *MergeFaceToList (face_t *face, face_t *list);
  188. face_t *FreeMergeListScraps (face_t *merged);
  189. void MergeAll (surface_t *surfhead);
  190.  
  191. /*============================================================================= */
  192.  
  193. /* surfaces.c */
  194.  
  195. extern    int        c_cornerverts;
  196. extern    int        c_tryedges;
  197. extern    face_t        *edgefaces[MAX_MAP_EDGES][2];
  198.  
  199. extern    int        firstmodeledge;
  200. extern    int        firstmodelface;
  201.  
  202. void SubdivideFaces (surface_t *surfhead);
  203.  
  204. surface_t *GatherNodeFaces (node_t *headnode);
  205.  
  206. void MakeFaceEdges (node_t *headnode, int count);
  207.  
  208. /*============================================================================= */
  209.  
  210. /* portals.c */
  211.  
  212. typedef struct portal_s
  213. {
  214.     int            planenum;
  215.     node_t        *nodes[2];        /* [0] = front side of planenum */
  216.     struct portal_s    *next[2];    
  217.     winding_t    *winding;
  218. } portal_t;
  219.  
  220. extern    node_t    outside_node;        /* portals outside the world face this */
  221.  
  222. void PortalizeWorld (node_t *headnode);
  223. void WritePortalfile (node_t *headnode);
  224. void FreeAllPortals (node_t *node);
  225.  
  226. /*============================================================================= */
  227.  
  228. /* region.c */
  229.  
  230. void GrowNodeRegions (node_t *headnode);
  231.  
  232. /*============================================================================= */
  233.  
  234. /* tjunc.c */
  235.  
  236. void tjunc (node_t *headnode);
  237.  
  238. /*============================================================================= */
  239.  
  240. /* writebsp.c */
  241.  
  242. int WriteNodePlanes (node_t *headnode);
  243. void WriteClipNodes (node_t *headnode);
  244. void WriteDrawNodes (node_t *headnode);
  245.  
  246. void BumpModel (int hullnum);
  247. int FindFinalPlane (dplane_t *p);
  248.  
  249. void BeginBSPFile (void);
  250. void FinishBSPFile (void);
  251.  
  252. /*============================================================================= */
  253.  
  254. /* draw.c */
  255.  
  256. void Draw_ClearBounds (void);
  257. void Draw_AddToBounds (vec3_t v);
  258. void Draw_DrawFace (face_t *f);
  259. void Draw_ClearWindow (void);
  260. void Draw_SetRed (void);
  261. void Draw_SetGrey (void);
  262. void Draw_SetBlack (void);
  263. void DrawPoint (vec3_t v);
  264.  
  265. void Draw_SetColor (int c);
  266. void SetColor (int c);
  267. void DrawPortal (portal_t *p);
  268. void DrawLeaf (node_t *l, int color);
  269. void DrawBrush (brush_t *b);
  270.  
  271. void DrawWinding (winding_t *w);
  272. void DrawTri (vec3_t p1, vec3_t p2, vec3_t p3);
  273.  
  274. /*============================================================================= */
  275.  
  276. /* outside.c */
  277.  
  278. qboolean FillOutside (node_t *node);
  279.  
  280. /*============================================================================= */
  281.  
  282. extern    qboolean    drawflag;
  283. extern    qboolean nofill;
  284. extern    qboolean notjunc;
  285. extern    qboolean noclip;
  286. extern    qboolean    verbose;
  287.  
  288. extern    int        hullnum;
  289.  
  290. extern    brushset_t    *brushset;
  291.  
  292. void qprintf (char *fmt, ...);    /* only prints if verbose */
  293.  
  294. extern    int        valid;
  295.  
  296. extern    char    portfilename[1024];
  297. extern    char    bspfilename[1024];
  298. extern    char    pointfilename[1024];
  299.  
  300. extern    char    projectpath[1024];    /* with a trailing slash, for finding wads */
  301.  
  302. extern    qboolean    worldmodel;
  303.  
  304.  
  305. /* misc functions */
  306.  
  307. face_t *AllocFace (void);
  308. void FreeFace (face_t *f);
  309.  
  310. struct portal_s *AllocPortal (void);
  311. void FreePortal (struct portal_s *p);
  312.  
  313. surface_t *AllocSurface (void);
  314. void FreeSurface (surface_t *s);
  315.  
  316. node_t *AllocNode (void);
  317. struct brush_s *AllocBrush (void);
  318.  
  319. /*============================================================================= */
  320.  
  321. #define malloc qmalloc
  322. #define free qfree
  323.  
  324.